﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SIS_Wcf_Server;
using SIS_Wcf_Server.Model;

namespace SIS_Wcf_Server.Search
{
    public class GpsSnifferDecorator : ISearch
    {




        ISearch _inner;
        IData   _data;

        public GpsSnifferDecorator(IData data, ISearch inner)
        {
            _inner = inner;
            _data = data;
        }



        #region ISearch Members

        public List<Model.RestInformation> DoSearch(List<Model.Lokation> locations)
        {
            List<Model.RestInformation> result = _inner.DoSearch( locations );
            bool bGotGps = false;

            foreach (Lokation l in locations)
            {
                if (l.isGps())
                {
                    bGotGps = true;
                    break;
                }
            }

            if (bGotGps)
            {
                // Find netId for alle de nets der er her, og tag dem som "ikke geocodede"
                foreach ( Lokation l in locations )
                {
                    if ( ! l.isGps( ) )
                    {
                        _data.tagLokationAsNoneGeoCoded(l);
                    }
                }
            }

            return result;
        }
             
        public List<Model.RestInformation> DoListAll()
        {
            return _inner.DoListAll();
        }

        #endregion
    }
}